# -*- coding: utf-8 -*-
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TuringClass.settings')
import django
from app_TuringClass.models import *
from app_accounts.models import *
from django.contrib.auth.models import User
import datetime
## author：houchaoqun
## function：初始化用户数据库
## date：2016/11/10

def Population():
	### UserID, PassWord, RoleTypeID, NickName
	# EnshrineString: 002 高数，001 C++
	AddNewVolunteer('Volunteer_test1', '123456', 'volunteer', '志愿者_test1', "838084986@qq.com", "838084986", "15359601555", "002")
	AddNewVolunteer('Volunteer_test2', '123456', 'volunteer', '志愿者_test2', "888888888@qq.com", "888888888", "15359601555", "001")

	# ### RoleTypeID, RoleTypeName, DeletePermission, PostPermission, SuperPermission
	# AddNewRoleType('admin', '管理员', True, True, True)
	# AddNewRoleType('student', '学生用户', True, True, False)
	# AddNewRoleType('volunteer', '志愿者', False, False, False)


def AddNewVolunteer(UserID, PassWord, RoleTypeID, NickName, UserEmail, UserQQ, MobilePhone, EnshrineString):
	print "[UserID] = ",UserID
	if TuringUser.objects.filter(UserID = UserID).exists():
		print "[User has been existed...]"
	else:
		if TuringUser.objects.filter(UserEmail = UserEmail).exists():
			print UserID,"[UserEmail has been existed...]"
		else:
			NewUser = User.objects.create_user(username = UserID, password = PassWord)
			NewTuringUser = TuringUser.objects.get_or_create(CurrentTime=timezone.now(), LastLoginTime=timezone.now(), Users = NewUser, UserID = UserID, RoleTypeID = RoleTypeID, NickName = NickName, UserEmail = UserEmail, UserQQ = UserQQ, MobilePhone = MobilePhone, EnshrineString = EnshrineString)[0]
			NewTuringUser.save()
			print "-- function [AddNewUsers] successful... "

### main program
if __name__ == '__main__':
	print 'DB_Volunteer.py - running...'
	Population()
